class Admin::SitesController < Admin::AdminApplicationController
  layout "admin"
  before_filter :admin_login_required
  
  def index
    @sites = Site.paginate :page => params[:page], :order => "created_at desc"
  end
  
  def search
    if params[:search_type].nil?
      redirect_back_or_default admin_sites_url
    elsif params[:search_type] == 'id'
      @site = Site.find(:first, :conditions => ["id = ?", params[:q]])
    elsif params[:search_type] == 'content'
      #@sites = Site.find_by_contents(params[:q])
      @sites = Site.paginate_search(params[:q], {:page => params[:page]})
    else
      redirect_back_or_default admin_sites_url
    end
  end
  
  def show
    @site = Site.find(params[:id])
  end
  
  def edit
    @site = Site.find(params[:id])
  end
  
  def update
    @site = Site.find(params[:id])
    @site.update_attributes(params[:site])
    redirect_to  admin_site_url(@site)
  end
  
  def destroy
    @site = Site.find(params[:id])
    @site.destroy
    
    redirect_to admin_sites_url
  end
  
end
